package com.skiving.cloud.config;

import com.zaxxer.hikari.HikariDataSource;
import com.zaxxer.hikari.metrics.prometheus.PrometheusMetricsTrackerFactory;
import io.micrometer.core.instrument.MeterRegistry;
import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.vault.annotation.VaultInject;

import javax.sql.DataSource;

@Configuration
public class DataSourceConfiguration {

    @Bean(value = "ds1", typed = true)
    public DataSource datasource(@VaultInject("${mybatis-flex.datasource.ds1}") HikariDataSource ds, MeterRegistry registry){
        ds.setMetricsTrackerFactory(new PrometheusMetricsTrackerFactory());
        return ds;
    }
    //多数据源
    @Bean(value = "ds2", typed = true)
    public DataSource ds2(@VaultInject("${mybatis-flex.datasource.ds2}") HikariDataSource ds, MeterRegistry registry){
        ds.setMetricsTrackerFactory(new PrometheusMetricsTrackerFactory());
        return ds;
    }
}
